package com.ctg.payroll2.service.payment.impl;

import java.sql.SQLException;
import java.util.List;

import com.ctg.payroll2.bean.filter.PayClassFilter;
import com.ctg.payroll2.bean.po.PayClass;
import com.ctg.payroll2.dao.payment.PayClassDAO;
import com.ctg.payroll2.service.payment.PayClassService;
import com.ctg.payroll2.util.Constants;
import com.ctg.platform.util.Page;

public class PayClassServiceImpl implements PayClassService {
	private PayClassDAO payClazzDao;
	
	public Page queryPayClassPageByFilter(PayClassFilter filter){
		return payClazzDao.queryPayClazzPageByFilter(filter);
	}

	public Long insertPayClass(PayClass payClazz){
		Long id =  payClazzDao.insertPayClazz(payClazz);
		return id;
	}
	
	public boolean fakeDeletePayClazzByIds(Long id){
//		先要判断该薪资类别是否与员工已经发生了关系再删除
		int empCount = payClazzDao.getEmployeeByPayClazzId(id);
		if(empCount==0){
			PayClass pay = new PayClass();
			pay.setPay_class_id(id);
			
			pay.setIs_valid(Constants.VALID_F);
			payClazzDao.fakeDeletePayClazzByIds(pay);
			return true;
		}else{
			return false;
		}
	}

	public PayClass retrieveEntity(Long id) {
		if (id==null) {
			return null;
		}
		
		List<PayClass> list = payClazzDao.queryForPayClazzById(id);
		return list.size()==1?list.get(0):null;
	}
	public void updatePayClazz(PayClass payClazz)  throws SQLException{
		payClazzDao.updatePayClazz(payClazz);
	}

	public void setPayClazzDao(PayClassDAO payClazzDao) {
		this.payClazzDao = payClazzDao;
	}
}
